package edu.arizona.arid.akshen.entity;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

/**
 * 
 * @author Sumin Byeon
 *
 */
public class Log extends Entity {
	
	public enum Type {
		Event,
		Exception,
	}
	
	private Date timetamp;
	private Type type;
	private String details;
	
	public Log() {
	}
	
	public Log(Type type, String details) {
		this.type = type;
		this.details = details;
		
		try {
			prepareConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Override
	public boolean insert() throws SQLException {
		
		PreparedStatement stmt = conn.prepareStatement("INSERT INTO log (type, timestamp, details) VALUES(?, ?, ?)");
		stmt.setString(1, type.toString());
		stmt.setLong(2, System.currentTimeMillis());
		stmt.setString(3, details);
		return stmt.execute();
	}
}
